﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using SerialozLibrary;

namespace SSS.AlphaNN.Components
{
    public partial class Dummy:UserControl
    {
        public DummyGhost GetGhost( Type dummyType )
        {
            DummyGhost dummyGhost = new DummyGhost();
            dummyGhost.noneScaleSize = this.NoneScaleSize;
            dummyGhost.noneScaleLocation = this.NoneScaleLocation;
            dummyGhost.dummyType = dummyType;
            dummyGhost.dummyID = this.Identificator;
            List<object> li=new List<object>();

            if ( this is Neuron )
            {

                li.Add( ( this as Neuron ).Offset );
                li.Add( ( this as Neuron ).IdActivationFunction );
                li.AddRange( ( this as Neuron ).ParametersForActivationFunction );
                dummyGhost.data=li.ToArray();
            }
            else
            {
                if ( this is DataMedium )
                {
                    li.Add( ( this as DataMedium ).PathFileDb );
                    li.Add( ( this as DataMedium ).Login );
                    li.Add( ( this as DataMedium ).Query );
                    li.Add( ( this as DataMedium ).countSignal );
                    if ( this is Sink )
                    {
                        li.Add( ( this as Sink ).DateAndTime );
                        li.Add( ( this as Sink ).typeFileInput );

                    }
                    else
                    {
                        if ( this is Teacher )
                        {
                            li.Add( ( this as Teacher ).countLearning );
                            li.Add( ( this as Teacher ).epsilon );
                            li.Add( ( this as Teacher ).coefficientLearning );
                            li.Add( ( this as Teacher ).SpeedLearning );
                        }
                    }
                    dummyGhost.data=li.ToArray();
                }
            }
            return dummyGhost;
        }


        /// <summary>
        /// Конструктор
        /// </summary>
        public Dummy()
        {
            InitializeComponent();
            Identificator = privateIndex;
            privateIndex++;

            this.Visible = false;

            this.DoubleBuffered = false;

            NoneScaleSize = this.Size;
        }

        /*
         * Props
         * =============================
         */

        /// <summary>
        /// 
        /// </summary>
        Point temporalPoint;

        /// <summary>
        /// 
        /// </summary>
        public Point TemporalPoint
        {
            get
            {
                return temporalPoint;
            }
            set
            {
                temporalPoint = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        Size noneScaleSize;

        /// <summary>
        /// 
        /// </summary>
        public Size NoneScaleSize
        {
            get
            {
                return noneScaleSize;
            }
            set
            {
                noneScaleSize = value;
                // this.Refresh();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        Point noneScaleLocation;

        /// <summary>
        /// 
        /// </summary>
        public Point NoneScaleLocation
        {
            get//; set;
            {
                return noneScaleLocation;
            }
            set
            {
                noneScaleLocation = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        bool marked = false;

        /// <summary>
        /// 
        /// </summary>
        public bool Mark
        {
            set
            {
                borderColor = ( marked = value ) ? _markedBorderColor : _baseBorderColor;
                //this.Refresh();
            }
            get
            {
                return marked;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public float Zoom
        {
            get
            {
                return ( this.Parent as WorkGround ).Zoom;
            }
        }


        /*
         * Fields
         * ===================================
         */

        /// <summary>
        /// 
        /// </summary>
        Color _baseBorderColor = Color.Black;

        /// <summary>
        /// 
        /// </summary>
        Color _markedBorderColor = Color.Crimson;

        public Pen MarkedBorderColor
        {
            get
            {
                return new Pen( _markedBorderColor );
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected Color borderColor = Color.Black;

        /// <summary>
        /// 
        /// </summary>
        List<Slot> slots = new List<Slot>();

        /// <summary>
        /// 
        /// </summary>
        public List<Slot> Slots
        {
            get
            {
                return slots;
            }
            set
            {
                slots = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        Point md;

        /*
         * Methods
         * ===============================
         */

        /// <summary>
        /// 
        /// </summary>
        /// <param name="show"></param>
        /// <param name="forceUnmark"></param>
        delegate void ShowSlotsHandler( bool show, bool forceUnmark );


        /// <summary>
        /// 
        /// </summary>
        public void ShowSlots()
        {
            for ( int i = 0; i < slots.Count; i++ )
            {
                slots[i].Visible = true;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void HideSlots()
        {
            for ( int i = 0; i < slots.Count; i++ )
            {
                slots[i].Visible = false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public SlotStateEnum MarkSlotsAsHasToBeShown
        {
            set
            {
                for ( int i = 0; i < slots.Count; i++ )
                {
                    slots[i].SlotState = value;
                }
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public virtual void ReLocate()
        {
            //this.Location = new Point( ( int )( this.noneScaleLocation.X + this.noneScaleLocation.X * Zoom / 100 ), ( int )( this.noneScaleLocation.Y + this.noneScaleLocation.Y * Zoom / 100 ) );
        }

        public virtual void CreateSlots()
        {//Это кусок кода мой - Савиных А. С.=) (почти Пушкин=) Не трогайте его
            if ( this is Source || this is Sink )
            {
                ( this as DataMedium ).SetSlotsAmount( ( this as DataMedium ).countSignal );
            }//конец кода
        }
        /// <summary>
        /// 
        /// </summary>
        public virtual void Scale()
        {
            //foreach ( Slot slot in slots )
            //{
            //    slot.SlotResize();
            //}

            this.Size = new Size( (int)( this.NoneScaleSize.Width + this.NoneScaleSize.Width * Zoom / 100 ), (int)( this.NoneScaleSize.Height + this.NoneScaleSize.Height * Zoom / 100 ) );

            this.Location = new Point( (int)( this.noneScaleLocation.X + this.noneScaleLocation.X * Zoom / 100 ), (int)( this.noneScaleLocation.Y + this.noneScaleLocation.Y * Zoom / 100 ) );

            //this.Location = new Point( ( int )( this.Location.X + this.Location.X * Zoom / 100 ), ( int )( this.Location.Y + this.Location.Y * Zoom / 100 ) );
        }


        public Color current_color = Color.Azure;
        Color default_color = Color.Azure;
        Color anim_color = Color.Red;


        public virtual void DoAnimate()
        {
            if ( current_color != anim_color )
            {
                current_color = anim_color;
            }
            else
            {
                current_color = default_color;
            }



            this.Parent.Invalidate();


        }

        #region Timers

        /// <summary>
        /// 
        /// </summary>
        public System.Threading.Timer selfShadeTimer;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Dummy_MouseLeave( object sender, EventArgs e )
        {
            mouseHoverTimer.Dispose();
            selfShadeTimer = new System.Threading.Timer( SelfShadeTimerTick, null, 300, 0 );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        private void SelfShadeTimerTick( object o )
        {
            HideSlots();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Dummy_MouseEnter( object sender, EventArgs e )
        {
            mouseHoverTimer = new System.Threading.Timer( TimerTick, null, 300, 0 );
        }

        /// <summary>
        /// 
        /// </summary>
        System.Threading.Timer mouseHoverTimer;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        private void TimerTick( object o )
        {
            HideSlots();
        }

        #endregion



    }
}
